package com.nintendo.bubblechat.service.impl;

import com.nintendo.bubblechat.entity.pojo.ChatMsg;
import com.nintendo.bubblechat.entity.pojo.ChatSnapshot;
import com.nintendo.bubblechat.entity.pojo.FriendsRequest;
import com.nintendo.bubblechat.entity.pojo.GroupChatMsg;
import com.nintendo.bubblechat.entity.vo.GroupChatMsgVo;
import com.nintendo.bubblechat.mapper.ChatMsgMapper;
import com.nintendo.bubblechat.service.ChatMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ChatMsgServiceImpl implements ChatMsgService {
    @Autowired
    private ChatMsgMapper chatMsgMapper;

    @Override
    public List<String> findMyUnReadMsg(FriendsRequest friendRequest) {
        List<ChatMsg> myUnReadMsg = chatMsgMapper.findMyUnReadMsg(friendRequest);
        List<String> list = new ArrayList<>();
        myUnReadMsg.forEach(chatMsg -> list.add(chatMsg.getId()));
        return list;
    }

    @Override
    public List<ChatSnapshot> getChatSnapshot(String acceptUserId) {
        return chatMsgMapper.getChatSnapshot(acceptUserId);
    }

    @Override
    public List<ChatMsg> findChatHistory(FriendsRequest friendRequest) {
        return chatMsgMapper.findChatHistoryList(friendRequest);
    }

    @Override
    public List<GroupChatMsgVo> findGroupChatList(String groupId) {
        List<GroupChatMsgVo> groupChatMsgVos =  chatMsgMapper.findGroupChatList(groupId);
        return groupChatMsgVos;
    }

    @Override
    public List<GroupChatMsgVo> findGroupNewMsg(List<String> groupIds) {
       return  chatMsgMapper.findGroupNewMsg(groupIds);
    }
}
